package com.qdu.service.impl;

import com.qdu.entity.Houseinfo;
import com.qdu.mapper.HouseinfoMapper;
import com.qdu.service.HouseService;
import com.qdu.util.GenerateUUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class HouseServiceImpl implements HouseService {

    @Autowired
    private HouseinfoMapper houseinfoMapper;

    @Override
    public void deleteByPrimaryKey(String hid) {
        houseinfoMapper.deleteByPrimaryKey(hid);
    }

    @Override
    public void insert(Houseinfo record) {
        record.setHid("H"+ GenerateUUID.generateUUID());
        houseinfoMapper.insert(record);
    }

    @Override
    public void insertSelective(Houseinfo record) {
        houseinfoMapper.insertSelective(record);
    }

    @Override
    public Houseinfo selectByHid(String hid) {
        return houseinfoMapper.selectByPrimaryKey(hid);
    }

    @Override
    public List<Houseinfo> selectByUid(String uid) {
        return houseinfoMapper.selectByUid(uid);
    }

    @Override
    public List<Houseinfo> selectByKey(String keys) {
        return houseinfoMapper.getByKey(keys);
    }

    @Override
    public List<Houseinfo> selectByLotsKeys(String mode, int pricelow, String type, int term, int floorlow) {
        int pricetop = 0;
        if(pricelow == 0){
            pricetop = 1500;
        }else if(pricelow == 3500){
            pricetop = Integer.MAX_VALUE;
        }else{
            pricetop=pricelow+500;
        }
        int floortop = 0;
        if(floorlow == 1){
            floortop = 6;
        }else if(floorlow == 7){
            floortop = 18;
        }else{
            floortop = Integer.MAX_VALUE;
        }
        List<Houseinfo> houseinfos=houseinfoMapper.getByLotsKeys(mode,pricelow,pricetop,type,term,floorlow,floortop);
        return houseinfos;
    }

    @Override
    public void updateByPrimaryKeySelective(Houseinfo record) {
        houseinfoMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public void updateByPrimaryKey(Houseinfo record) {
        houseinfoMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Houseinfo> getAll() {
        return houseinfoMapper.getAll();
    }

    @Override
    public List<Houseinfo> getHouseByPage(Integer start, Integer rows) {
        return houseinfoMapper.getHouseByPage(start,rows);
    }

    @Override
    public Long findTotals() {
        return houseinfoMapper.findTotals();
    }
}
